def binary_search(a, x):
    low = 0
    high = len(a) - 1
    i = -1  # 记录小于x的最大元素位置i
    j = -1  # 记录大于x的最小元素位置j

    while low <= high:
        mid = (low + high) // 2

        if a[mid] == x:
            return mid, mid

        if a[mid] < x:
            low = mid + 1
            i = mid
        else:
            high = mid - 1
            j = mid

    return i, j

# 示例用法
a = [2, 4, 6, 8, 10, 12]
x = 6
i, j = binary_search(a, x)
print("小于x的最大元素位置:", i)
print("大于x的最小元素位置:", j)
